<template>
  <!-- 底部部分 -->
  <footer class="footer" v-if="list.length > 0">
    <span class="todo-count"
      ><strong>{{ leftCount }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a class="selected" href="#/">全部</a>
      </li>
      <li>
        <a href="#/active">进行中</a>
      </li>
      <li>
        <a href="#/completed">已完成</a>
      </li>
    </ul>
    <button class="clear-completed" v-show="isShowClear" @click="clear">
      清除已完成
    </button>
  </footer>
</template>
<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
  },
  computed: {
    leftCount() {
      const arr = this.list.filter((item) => !item.isDone)
      return arr.length
    },
    isShowClear() {
      return this.list.some((item) => item.isDone)
    },
  },
  methods: {
    clear() {
      // 清空已经完成的任务  过滤，保留未完成的任务
      this.$emit('clear')
    },
  },
}
</script>
